#ifndef _OHAI_XMPP_H_
#define _OHAI_XMPP_H_

/* XMPP/jabber related routines.
 *
 * Copyright 2008 Cian Synnott.
 * 
 * $Id: xmpp.h 28 2009-12-04 03:01:17Z cian $
 */
typedef struct _xmpp_session xmpp_session;

/* Sets up an xmpp connection and callbacks.
 *
 * Args:
 * - jid: A jabber id, e.g. cian@example.com/resource
 * - password: User password
 * - server: Server to connect to, if different from the jid host part
 * - port: Port to connect to, if different from jabber's default port
 * - status: Initial status message or NULL for a generic message.
 * Returns:
 * - xmpp_session structure for controlling this new session
 */
xmpp_session *xmpp_setup(char *jid, char *password, char *server, int port,
  char *status);

/* Set/send the status within an xmpp session.
 *
 * Args:
 * - session: an xmpp_session
 * - status: 0 for unavailable, 1 for available
 * - message: new status message to send
 */
void xmpp_set_status(xmpp_session *sess, int status, char *message);
void xmpp_send_status(xmpp_session *sess);

/* Get a list of status structures for the xmpp session's roster.
 *
 * Args:
 * - session: an xmpp_session
 * Returns:
 * - A pointer to the head of an xmpp_status list.
 */
typedef struct _xmpp_status {
  char *jid;
  char *show;     /* away, unavailable, available, etc. */
  char *message;  /* status message if set, NULL otherwise. */
  struct _xmpp_status *next;
} xmpp_status; 

xmpp_status *xmpp_get_contact_status(xmpp_session *sess);

/* Get a list of messages to be delivered to the user.
 *
 * Note that the caller is responsible for freeing the
 * returned list of messages.
 *
 * Args:
 * - session: an xmpp_session
 * Returns:
 * - A pointer to the head of an xmpp_user_message list.
 */
typedef struct _xmpp_user_message {
  char *message;
  struct _xmpp_user_message *next;
} xmpp_user_message; 

xmpp_user_message *xmpp_get_user_messages(xmpp_session *sess);

/* Send an xmpp message.
 *
 * Args:
 * - session: an xmpp_session
 * - to: jid of the receiver
 * - message: body of the message
 */
void xmpp_send_message(xmpp_session *sess, char *to, char *message);

/* Frees resources associated with an xmpp session.
 *
 * Args:
 * - sess: an xmpp_session to tear down
 */
void xmpp_teardown(xmpp_session *sess);

#endif /* _OHAI_XMPP_H_ */
